//
//  DBManager.h
//  ModelContrast
//
//  Created by Cluy on 15/7/14.
//  Copyright (c) 2015年 sunflowers. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FMDatabase.h"
#import "FMDatabaseAdditions.h"

@interface DBManager : NSObject

@property (strong, nonatomic) FMDatabase *DB;
@property (strong, nonatomic) NSString *DBName;

- (id)initWithDBName:(NSString *)dbName;
// 删除数据库
- (void)deleteDatabse;

// 打开数据库
- (BOOL)readyDatabse;
- (void)openDB;
- (void)closeDB;
// 判断是否存在表
- (BOOL) isTableOK:(NSString *)tableName;
// 获得表的数据条数
- (NSInteger) getTableItemCount:(NSString *)tableName;

// 创建表
- (BOOL) createTable:(NSString *)tableName fields:(NSArray *)fields;
// 删除表-彻底删除表
- (BOOL) deleteTable:(NSString *)tableName;
// 清除表-清数据
- (BOOL) eraseTable:(NSString *)tableName;

/*
 * 插入
 * 参数【tableName:表名】【sqlParam:插入这一行的值】
 * 返回类型为 NSArray
 */
- (BOOL)insertTable:(NSString*)tableName  withArr:(NSArray *)sqlParam;

/*
 * 查询
 * 参数【tableName:表名】【fields:返回的字段集】
 【whereStr: where条件】【groupByParam:group 条件】
 【orderbyParam:orderby 条件】【desc YES:为倒叙 No:为正序】
 * 返回类型为 NSArray
 */
- (NSArray *)selectFromTable:(NSString*)tableName fields:(NSArray*)fields whereParam:(NSString *)whereStr
                groupBy:(NSArray*)groupByParam orderby:(NSArray*)orderbyParam desc:(BOOL)desc;

// 修改数据
- (BOOL)updateTable:(NSString*)sql, ...;





@end
